package cn.yz.controller;


import cn.yz.entity.AccountBill;
import cn.yz.dto.AccountBillDto;
import cn.yz.dto.AccountBillPageDto;
import cn.yz.result.Result;
import cn.yz.service.AccountBillService;
import cn.yz.vo.AccountBillVo;
import cn.yz.vo.PageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 账单表(AccountBill)控制层
 *
 * @author yangzhen
 * @since 2025-07-14 14:59:10
 */
@Tag(name = "账单表接口", description = "账单表接口")
@RestController
@RequestMapping("/v1/accountBill")
public class AccountBillController {

    /**
     * 服务对象
     */
    @Autowired
    private AccountBillService accountBillService;


    /**
     * 分页查询
     *
     * @param pageDto
     * @return
     */
    @Operation(summary = "账单表分页查询")
    @PostMapping("/paginationAccountBill")
    public Result<PageVo<AccountBillVo>> pagination(@RequestBody @Valid AccountBillPageDto pageDto) {
        return accountBillService.queryPage(pageDto);

    }

    /**
     * 不分页列表查询
     *
     * @param accountBillDto
     * @return
     */
    @Operation(summary = "账单表不分页查询")
    @PostMapping("/queryAccountBillList")
    public Result<List<AccountBillVo>> queryList(@RequestBody @Valid AccountBillDto accountBillDto) {
        return accountBillService.queryList(accountBillDto);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Operation(summary = "通过id查询账单表详情")
    @GetMapping("/queryInfoById/{id}")
    public Result<AccountBillVo> queryInfoById(@PathVariable("id") String id) {
        AccountBill entity = accountBillService.getById(id);
        return entity == null ? Result.error("查询结果为空") : Result.success(entity.toVo(AccountBillVo.class));
    }


    /**
     * 新增账单表
     *
     * @param accountBillDto
     * @return
     */
    @Operation(summary = "新增账单")
    @PostMapping("/addAccountBill")
    public Result<Void> add(@RequestBody @Valid AccountBillDto accountBillDto) {
        return accountBillService.insert(accountBillDto);
    }

    /**
     * 修改
     *
     * @param accountBillDto
     * @return
     */
    @Operation(summary = "修改账单表")
    @PutMapping("/editAccountBill")
    public Result<Void> edit(@Valid @RequestBody AccountBillDto accountBillDto) {
        return accountBillService.update(accountBillDto);
    }


    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Operation(summary = "删除账单表")
    @DeleteMapping("/delAccountBill/{id}")
    public Result<Void> del(@PathVariable("id") String id) {
        return accountBillService.delete(id);
    }

}
